
var util = require('../../utils/util.js');
var baseImgUrl=util.baseImgUrl;
var verifyIdentity=util.verifyIdentity;
let app = getApp();
let jumpurl = util.jumpurl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    top_back:baseImgUrl+"top_back.png",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: jumpurl + 'my/kefu',
      data: {
        openid: app.globalData.openid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        that.setData({
          title : res.data.title,
          sever_tel: res.data.sever_tel,
          sever_wxNum: res.data.sever_wxNum,
          sever_time: res.data.sever_time,
        })
      },
    })
  },

 
  formBindsubmit: function (mobile) {
    console.log(mobile)
    console.log(mobile.detail.value.list_word)
    var phone = mobile.detail.value.phone;
    var list_word= mobile.detail.value.list_word;

    if (phone.length == 0) {
      wx.showToast({
        title: '您还没有填写手机号',
        icon: 'none',
        duration: 1500
      })
      return false;
    }
    if (phone.length != 11) {
      wx.showToast({
        title: '手机号长度有误！',
        icon: 'none',
        duration: 1500
      })
      return false;
    }
    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (!myreg.test(phone)) {
      wx.showToast({
        title: '手机号有误！',
        icon: 'none',
        duration: 1500
      })
      return false;
    }
    if(list_word.length==0){
      wx.showToast({
        title: '您还没有填写留言',
        icon:"none",
        duration:1000
       })
       return false;
    }

    wx.showToast({
          title: '提交成功',
          icon:"success",
          duration:500
        })
        setTimeout(function(){
          wx.navigateTo({
            url: '/pages/mine/mine',
          })
        },300);
   //请求接口
    wx.request({
      url: jumpurl + "my/submit_kefu",
      data:{
        phone: phone,
        content:list_word, 
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success:function(res){
        console.log(res);
        wx.showToast({
          title: '提交成功',
          icon:"success",
          duration:500
        })
        setTimeout(function(){
          wx.switchTab({
            url: '/pages/mine/mine',
          })
        },300);
       
      },
      error:function(err){
          console.log(err);
      }
    })

      return true;
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})